$(function () {
    var lang = GetQueryString('lang');
    if (lang !== null) {
        $.cookie('locale', lang, {expires: 365, path: '/'});
    } else if ($.cookie('locale') === undefined){
        lang = (navigator.language || navigator.userLanguage).substr(0, 2);
        $.cookie('locale', lang, {expires: 365, path: '/'});
    } else {
        lang = $.cookie('locale');
    }
    $('#language').find('.language').text(lang.indexOf('en') !== -1 ? 'English' : '简体中文');
    jQuery.i18n.properties({
        name: 'charts',
        path: basePath + 'js/properties/',
        mode: 'map',
        language: lang || 'zh',
        async: false,
        callback: function () {
            $('[i18n]').each(function () {
                $(this).text($.i18n.prop($(this).attr('i18n')));
            });
            $('[i18n-title]').each(function () {
                $(this).attr('title', ($.i18n.prop($(this).attr('i18n-title'))));
            });
        }
    });
    window.$headerObj = {
        main: $('header'),
        page: {
            hospitalIndex: {
                url: ['charts/area/allocation/hospital-page', 'index/page'],
                name: $.i18n.prop('share.title.fx'),
                title: '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>',
                query: ['hospital', 'type', 'assets'],
                tag: 'hospital'
            },
            typeIndex: {
                url: 'charts/area/allocation/type-page',
                name: $.i18n.prop('share.title.sblx'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/type-page">' + $.i18n.prop('share.title.sblx') + '</a>'
                ),
                query: ['type', 'hospital', 'assets'],
                tag: 'type'
            },
            modelIndex: {
                url: 'charts/area/allocation/model-page',
                name: $.i18n.prop('share.title.sbxh'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/model-page">' + $.i18n.prop('share.title.sbxh') + '</a>'
                ),
                query: ['model', 'hospital', 'assets'],
                tag: 'model'
            },
            hospitalCost: {
                url: 'charts/area/cost/hospital-page',
                name: $.i18n.prop('share.title.fx') + '-' + $.i18n.prop('share.title.yyxl'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/cost/hospital-page">' + $.i18n.prop('share.title.yyxl') + '</a>'
                ),
                query: ['hospital', 'type', 'assets'],
                tag: 'hospital'
            },
            typeCost: {
                url: 'charts/area/cost/type-page',
                name: $.i18n.prop('share.title.sblx') + '-' + $.i18n.prop('share.title.yyxl'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/type-page">' + $.i18n.prop('share.title.sblx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/cost/type-page">' + $.i18n.prop('share.title.yyxl') + '</a>'
                ),
                query: ['type', 'hospital', 'assets'],
                tag: 'type'
            },
            modelCost: {
                url: 'charts/area/cost/model-page',
                name: $.i18n.prop('share.title.sbxh') + '-' + $.i18n.prop('share.title.yyxl'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/model-page">' + $.i18n.prop('share.title.sbxh') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/cost/model-page">' + $.i18n.prop('share.title.yyxl') + '</a>'
                ),
                query: ['model', 'hospital', 'assets'],
                tag: 'model'
            },
            hospitalMaintain: {
                url: 'charts/area/maintain/hospital-page',
                name: $.i18n.prop('share.title.fx') + '-' + $.i18n.prop('share.title.wxqk'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/maintain/hospital-page">' + $.i18n.prop('share.title.wxqk') + '</a>'
                ),
                query: ['hospital', 'type', 'brand', 'maintainer', 'assets'],
                tag: 'hospital'
            },
            typeMaintain: {
                url: 'charts/area/maintain/type-page',
                name: $.i18n.prop('share.title.sblx') + '-' + $.i18n.prop('share.title.wxqk'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/type-page">' + $.i18n.prop('share.title.sblx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/maintain/type-page">' + $.i18n.prop('share.title.wxqk') + '</a>'
                ),
                query: ['type', 'hospital', 'brand', 'maintainer', 'assets'],
                tag: 'type'
            },
            modelMaintain: {
                url: 'charts/area/maintain/model-page',
                name: $.i18n.prop('share.title.sbxh') + '-' + $.i18n.prop('share.title.wxqk'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/model-page">' + $.i18n.prop('share.title.sbxh') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/maintain/model-page">' + $.i18n.prop('share.title.wxqk') + '</a>'
                ),
                query: ['model', 'hospital', 'brand', 'maintainer', 'assets'],
                tag: 'model'
            },
            hospitalMaintenance: {
                url: 'charts/area/maintenance/hospital-page',
                name: $.i18n.prop('share.title.fx') + '-' + $.i18n.prop('share.title.whqk'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/maintenance/hospital-page">' + $.i18n.prop('share.title.whqk') + '</a>'
                ),
                query: ['hospital', 'type', 'assets'],
                tag: 'hospital'
            },
            typeMaintenance: {
                url: 'charts/area/maintenance/type-page',
                name: $.i18n.prop('share.title.sblx') + '-' + $.i18n.prop('share.title.whqk'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/type-page">' + $.i18n.prop('share.title.sblx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/maintenance/type-page">' + $.i18n.prop('share.title.whqk') + '</a>'
                ),
                query: ['type', 'hospital', 'assets'],
                tag: 'type'
            },
            modelMaintenance: {
                url: 'charts/area/maintenance/model-page',
                name: $.i18n.prop('share.title.sbxh') + '-' + $.i18n.prop('share.title.whqk'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/model-page">' + $.i18n.prop('share.title.sbxh') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/maintenance/model-page">' + $.i18n.prop('share.title.whqk') + '</a>'
                ),
                query: ['model', 'hospital', 'brand', 'assets'],
                tag: 'model'
            },
            hospitalBrand: {
                url: 'charts/area/brand/hospital-page',
                name: $.i18n.prop('share.title.fx') + '-' + $.i18n.prop('share.table.head.sbcj'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/brand/hospital-page">' + $.i18n.prop('share.table.head.sbcj') + '</a>'
                ),
                query: ['hospital', 'type', 'model', 'assets'],
                tag: 'hospital'
            },
            typeBrand: {
                url: 'charts/area/brand/type-page',
                name: $.i18n.prop('share.title.sblx') + '-' + $.i18n.prop('share.table.head.sbcj'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/type-page">' + $.i18n.prop('share.title.sblx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/brand/type-page">' + $.i18n.prop('share.table.head.sbcj') + '</a>'
                ),
                query: ['type', 'hospital', 'model', 'assets'],
                tag: 'type'
            },
            hospitalMaintainer: {
                url: 'charts/area/maintainer/hospital-page',
                name: $.i18n.prop('share.title.fx') + '-' + $.i18n.prop('share.table.head.wxs'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/maintainer/hospital-page">' + $.i18n.prop('share.table.head.wxs') + '</a>'
                ),
                query: ['hospital', 'type', 'model'],
                tag: 'hospital'
            },
            typeMaintainer: {
                url: 'charts/area/maintainer/type-page',
                name: $.i18n.prop('share.title.sblx') + '-' + $.i18n.prop('share.table.head.wxs'),
                title: (
                    '<a href="' + basePath + 'charts/area/allocation/hospital-page">' + $.i18n.prop('share.title.fx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/allocation/type-page">' + $.i18n.prop('share.title.sblx') + '</a>-' +
                    '<a href="' + basePath + 'charts/area/maintainer/type-page">' + $.i18n.prop('share.table.head.wxs') + '</a>'
                ),
                query: ['type', 'hospital', 'model'],
                tag: 'type'
            }
        },
        init: function () {
            this.setPage();
            this.setTitle();
            this.queryTime();
            this.bindEvent();
            this.searchObj.init();
        },
        setPage: function () {
            for (var key in this.page) {
                if (typeof this.page[key].url === 'object') {
                    for (var i = 0; i < this.page[key].url.length; i++) {
                        if (location.href.indexOf(this.page[key].url[i]) !== -1) {
                            this.page.current = key;
                            this.page.previous = localStorage.getItem('previous_page');
                            localStorage.setItem('previous_page', key);
                            this.page.tag = this.page[key].tag;
                        }
                    }
                } else {
                    if (location.href.indexOf(this.page[key].url) !== -1) {
                        this.page.current = key;
                        this.page.previous = localStorage.getItem('previous_page');
                        localStorage.setItem('previous_page', key);
                        this.page.tag = this.page[key].tag;
                    }
                }
            }
            if (this.page.current.indexOf('Index') !== -1) {
                this.main.find('.select_month').closest('tr').hide();
            }
        },
        setTitle: function () {
            var headerPage = this.main.find('#header-page'),
                str = this.page[this.page.current].title;
            headerPage.html(str || headerPage.html());
        },
        queryTime: function () {
            var $this = this;
            publicAjax(basePath + 'area/search/time', 'post', null, function (data) {
                $this.main.find('.time').html($.i18n.prop('share.title.jzrq') + '：' + data.data.time);
            }, true);
        },
        bindEvent: function () {
            /* 打开关闭筛选条件 */
            this.main.find('.header-search').on('click', this.searchObj.toggle.bind(this.searchObj));
            /* 重置筛选条件并刷新页面 */
            this.main.find('.header-reset').on('click', this.reset.bind(this));
            /* 登出 */
            this.main.find('.header-logout').on('click', this.logout.bind(this));

            /* 监听回退事件 */
            /*window.history.pushState({
              title: document.title,
              url: location.href
            }, document.title, location.href);
            setTimeout(function () {
              window.addEventListener("popstate", function (a) {
                alert('回退');
                history.go(-1);
                return false;
              })
            }, 20);*/
        },
        reset: function () {
            localStorage.setItem('search_params', null);
            location.reload();
        },
        logout: function () {
            this.searchObj.reset();
            location.href = basePath + '/logout';
        }
    };

    // 筛选条件对象
    $headerObj.searchObj = {
        main: $headerObj.main.find('#search-container'),
        params: {},
        data: {},
        formDataEl: {},
        queryDataStatus: {
            hospital: false,
            level: false,
            type: false,
            risk: false,
            brand: false,
            year: false,
            priceStart: false
        },
        init: function () {
            this.setFormDataEl();
            this.initLayout();
            this.initICheck();
            this.bindEvent();
            this.queryData('hospital');
            this.queryData('level');
            this.queryData('type');
            this.queryData('risk');
            this.queryData('brand');
            this.queryData('year');
        },
        initParams: function () {
            var params = this.getParamsFormLs();
            this.setParams(params);
            this.setParamsToForm(params);
            this.setParamsToLs(params);
            $containerObj.init();
        },
        setFormDataEl: function () {
            this.formDataEl.level = this.main.find('.select_level');
            this.formDataEl.hospital = this.main.find('.select_hospital');
            this.formDataEl.risk = this.main.find('.select_risk');
            this.formDataEl.type = this.main.find('.select_type');
            this.formDataEl.brand = this.main.find('.select_brand');
            this.formDataEl.year = this.main.find('.select_year');
            this.formDataEl.monthId = this.main.find('.select_month');
            this.formDataEl.enableYearStart = this.main.find('#enableYearStart');
            this.formDataEl.enableYearEnd = this.main.find('#enableYearEnd');
            this.formDataEl.priceStart = this.main.find('#priceStart');
            this.formDataEl.priceEnd = this.main.find('#priceEnd');
            this.formDataEl.ageLimitStart = this.main.find('#ageLimitStart');
            this.formDataEl.ageLimitEnd = this.main.find('#ageLimitEnd');
        },
        getParamsFormLs: function () {
            var params = JSON.parse(localStorage.getItem('search_params')) || {};
            if (GetQueryString('typeId')) {
                if (GetQueryString('typeId').indexOf('[') !== -1) {
                    params.typeId = GetQueryString('typeId');
                } else {
                    params.typeId = JSON.stringify([GetQueryString('typeId')]);
                }
            }
            if (GetQueryString('brandId')) {
                params.brandId = JSON.stringify([GetQueryString('brandId')]);
            }
            if (GetQueryString('maintainerId')) {
                params.maintainerId = GetQueryString('maintainerId');
            }
            return params;
        },
        getParamsFormForm: function () {
            var priceStart = this.formDataEl.priceStart.val();
            var priceEnd = this.formDataEl.priceEnd.val();
            priceStart = priceStart == '0'
                ? 0
                : priceStart ? priceStart * PRICE_CONVERT : '';
            priceEnd = priceEnd == '0'
                ? 0
                : priceEnd ? priceEnd * PRICE_CONVERT : '';
            return {
                levelId: JSON.stringify(this.formDataEl.level.val()),
                hospitalId: JSON.stringify(this.formDataEl.hospital.val()),
                riskId: JSON.stringify(this.formDataEl.risk.val()),
                typeId: JSON.stringify(this.formDataEl.type.val()),
                brandId: JSON.stringify(this.formDataEl.brand.val()),
                year: this.formDataEl.year.val(),
                monthId: this.formDataEl.monthId.val(),
                enableYearStart: this.formDataEl.enableYearStart.val(),
                enableYearEnd: this.formDataEl.enableYearEnd.val(),
                priceStart: priceStart,
                priceEnd: priceEnd,
                ageLimitStart: this.formDataEl.ageLimitStart.val(),
                ageLimitEnd: this.formDataEl.ageLimitEnd.val()
            };
        },
        setParams: function (params) {
            this.params = $.extend({}, params);
        },
        setParamsToForm: function (params) {
            var priceStart = params.priceStart == '0'
                ? 0
                : params.priceStart ? (params.priceStart / PRICE_CONVERT) : '';
            var priceEnd = params.priceEnd == '0'
                ? 0
                : params.priceEnd ? (params.priceEnd / PRICE_CONVERT) : '';
            this.formDataEl.level.val(JSON.parse(params.levelId || null)).trigger('change');
            this.formDataEl.hospital.val(JSON.parse(params.hospitalId || null)).trigger('change');
            this.formDataEl.risk.val(JSON.parse(params.riskId || null)).trigger('change');
            this.formDataEl.type.val(JSON.parse(params.typeId || null)).trigger('change');
            this.formDataEl.brand.val(JSON.parse(params.brandId || null)).trigger('change');
            this.formDataEl.year.val(params.year || null).trigger('change');
            this.formDataEl.monthId.val(params.monthId || null).trigger('change');
            this.formDataEl.enableYearStart.val(fixFD0(params.enableYearStart)).trigger('change');
            this.formDataEl.enableYearEnd.val(fixFD0(params.enableYearEnd)).trigger('change');
            this.formDataEl.priceStart.val(priceStart).trigger('change');
            this.formDataEl.priceEnd.val(priceEnd).trigger('change');
            this.formDataEl.ageLimitStart.val(fixFD0(params.ageLimitStart)).trigger('change');
            this.formDataEl.ageLimitEnd.val(fixFD0(params.ageLimitEnd)).trigger('change');
        },
        setParamsToLs: function (params) {
            var oldParams = JSON.parse(localStorage.getItem('search_params')) || {};
            if (GetQueryString('typeId') && GetQueryString('brandId')) {
                if (JSON.stringify([GetQueryString('typeId')]) === params.typeId) {
                    params.typeId = oldParams.typeId || null;
                }
                if (JSON.stringify([GetQueryString('brandId')]) === params.brandId) {
                    params.brandId = oldParams.brandId || null;
                }
            } else if (GetQueryString('typeId')) {
                if (JSON.stringify([GetQueryString('typeId')]) === params.typeId) {
                    params.typeId = oldParams.typeId || null;
                }
            } else if (GetQueryString('brandId')) {
                if (JSON.stringify([GetQueryString('brandId')]) === params.brandId) {
                    params.brandId = oldParams.brandId || null;
                }
            }
            params.brandId = undefined;
            params.maintainerId = undefined;
            params.maintainer = undefined;
            params.queryMin = undefined;
            params.queryMax = undefined;
            localStorage.setItem('search_params', JSON.stringify(params));
        },
        checkParams: function () {
            /* 启用年份验证 1990-2099正整数 */
            var enYs = this.formDataEl.enableYearStart;
            var enYe = this.formDataEl.enableYearEnd;
            if (/^((199\d{1})|(20\d{2})){0,1}$/.test(enYs.val()) && /^((199\d{1})|(20\d{2})){0,1}$/.test(enYe.val())) {
                if (enYs.val() && enYe.val() && (enYs.val() >= enYe.val())) {
                    enYs.addClass('error');
                    enYe.addClass('error');
                    flavrShowByTime($.i18n.prop('share.sift.qsrzqdqynxqj'), null, "danger", false);
                    return false;
                } else {
                    enYs.removeClass('error');
                    enYe.removeClass('error');
                    return true;
                }
            } else {
                enYs.addClass('error');
                enYe.addClass('error');
                flavrShowByTime($.i18n.prop('share.sift.qsrzjdnf'), null, "danger", false);
                return false;
            }
            /* 设备金额验证 正整数 */
            var ps = this.formDataEl.priceStart;
            var pe = this.formDataEl.priceEnd;
            if (/^\d*$/.test(ps.val()) && /^\d*$/.test(pe.val())) {
                if (ps.val() && pe.val() && (ps.val() >= pe.val())) {
                    ps.addClass('error');
                    pe.addClass('error');
                    flavrShowByTime($.i18n.prop('share.sift.qsrzjdsbjeqj'), null, "danger", false);
                    return false;
                } else {
                    ps.removeClass('error');
                    enYe.removeClass('error');
                    return true;
                }
            } else {
                ps.addClass('error');
                pe.addClass('error');
                flavrShowByTime($.i18n.prop('share.sift.qsrzzs'), null, "danger", false);
                return false;
            }
            /* 年限指数验证 大于0的小数 */
            var as = this.formDataEl.ageLimitStart;
            var ae = this.formDataEl.ageLimitEnd;
            if (/^\d*(\.\d*)?$/.test(as.val()) && /^\d*(\.\d*)?$/.test(ae.val())) {
                if (as.val() && ae.val() && (as.val() >= ae.val())) {
                    as.addClass('error');
                    ae.addClass('error');
                    flavrShowByTime($.i18n.prop('share.sift.qsrzqdnxzsqj'), null, "danger", false);
                    return false;
                } else {
                    as.removeClass('error');
                    ae.removeClass('error');
                    return true;
                }
            } else {
                as.addClass('error');
                ae.addClass('error');
                flavrShowByTime($.i18n.prop('share.sift.qsrdylds'), null, "danger", false);
                return false;
            }
        },
        initLayout: function () {
            this.width = this.main[0].clientWidth + 2;
            this.height = this.main[0].clientHeight + 2;
            this.main.find('form').width(this.width);
            this.main.find('form').height(this.height);
            this.main.css('width', 0);
            this.main.css('height', 0);
            /* 月份单独初始化 */
            this.main.find('.select_month').select2({
                placeholder: $.i18n.prop('share.sift.qxz'),
                allowClear: true,
                width: 4.8 * rem,
                minimumResultsForSearch: -1
            });
        },
        open: function () { // 打开筛选条件
            this.main.animate({
                width: this.width,
                height: this.height,
                opacity: 1
            }, 'slow');
        },
        close: function () {  // 关闭筛选
            var $this = this;
            this.main.animate({
                width: 0,
                height: 0,
                opacity: 0
            }, 'slow', function () {
                $this.setParamsToForm($this.params);
            });
        },
        toggle: function () { // toggle筛选
            if (this.main.css('opacity') > 0) {
                this.close();
            } else {
                this.open();
            }
        },
        reset: function () {  // 清空筛选条件
            for (var key in this.formDataEl) {
                this.formDataEl[key].val('').trigger('change');
            }
        },
        queryData: function (tag) {
            var $this = this;
            var url = basePath + 'area/search/' + tag;
            publicAjax(url, 'post', this.params, function (data) {
                $this.data[tag] = data.data;
                $this.queryDataStatus[tag] = true;
                $this.setData(tag);
            }, true);
        },
        setData: function (tag) {
            var data = this.data[tag];
            var first, second, id, str = '', str1;
            if (tag === "type") {
                str = '';
                first = data.first;
                for (var i = 0; i < first.length; i++) {
                    //一级设备
                    str += '<optgroup label="' + (first[i].name || "") + '">' +
                        (function () {
                            str1 = '';
                            id = first[i].id;
                            if (data[id]) {
                                //一级设备
                                str1 = '<option value="' + first[i].id + '">' + (first[i].name || "") + '</option>';
                                second = data[id];
                                for (var j = 0; j < second.length; j++) {
                                    //二级设备
                                    str1 += '<option value="' + second[j].id + '">' + (second[j].name || "") + '</option>';
                                }
                            } else {
                                str1 = '<option value="' + first[i].id + '">' + (first[i].name || "") + '</option>';
                            }
                            return str1;
                        })() +
                        '</optgroup>';
                }
                this.main.find(".select_type").append(str);
            } else {
                data = data ? data.list || [] : [];
                if (tag === 'hospital') {
                    for (var i = 0; i < data.length; i++) {
                        str += ('<option value="' + data[i].id + '">' + (data[i].name || "") + '</option>');
                    }
                    this.main.find(".select_" + 'hospital').append(str);
                } else {
                    for (var i = 0; i < data.length; i++) {
                        str += ('<option value="' + data[i].id + '">' + (data[i].name || "") + '</option>');
                    }
                    this.main.find(".select_" + tag).append(str);
                }
            }

            this.initSelect(tag);
            if (this.checkQueryDataStatus()) this.initParams();
        },
        checkQueryDataStatus: function () {
            for (var key in this.queryDataStatus) {
                if (!this.queryDataStatus[key]) return false;
            }
            return true;
        },
        initSelect: function (tag) {
            this.main.find('.select_' + tag).select2({
                placeholder: $.i18n.prop('share.sift.qxz'),
                allowClear: true,
                width: 4.8 * rem,
                minimumResultsForSearch: -1
            });
        },
        initICheck: function () {
            var $this = this;
            this.main.find('input[type="radio"].flat-green').iCheck({
                checkboxClass: 'icheckbox_flat-blue',
                radioClass: 'iradio_flat-blue'
            }).on('ifChecked', function () {
                var obj = $(this);
                var input = obj.closest('tr').prev().find('input.input');
                input.eq(0).val(obj.data().min);
                input.eq(1).val(obj.data().max);
            });

            publicAjax(basePath + 'area/search/price', 'post', {}, function (data) {
                var assetsPrice = $this.main.find('input[name="assets-price"]');
                $this.main.find('#priceStart').val(data.data.list[0].name);
                assetsPrice.eq(0).data().min = '';
                assetsPrice.eq(0).data().max = data.data.list[2].name;
                assetsPrice.eq(1).data().min = data.data.list[2].name;
                assetsPrice.eq(1).data().max = data.data.list[1].name;
                assetsPrice.eq(2).data().min = data.data.list[1].name;
                assetsPrice.eq(2).data().max = '';
                assetsPrice.eq(0).closest('label').find('span').text('>' + data.data.list[2].name);
                assetsPrice.eq(1).closest('label').find('span').text(data.data.list[2].name + '-' + data.data.list[1].name);
                assetsPrice.eq(2).closest('label').find('span').text('<' + data.data.list[1].name);

                $this.queryDataStatus.priceStart = true;
                if ($this.checkQueryDataStatus()) $this.initParams();
            }, true, {async: false});
        },
        bindEvent: function () {
            var $this = this;
            $(document).on('click', function (event) {
                if ((!$(event.target).isChildAndSelfOf("#search-container"))
                    && ($this.main.css('opacity') > 0)
                    && (event.target.className.indexOf('select2-selection__choice__remove') === -1)
                    && (!$(event.target).isChildAndSelfOf(".flavr-container"))) {
                    $this.close();
                }
            });
            this.main.find('.cancel').on('click', function () {
                $this.close();
            });
            this.main.find('.clear-search').on('click', function () {
                $this.reset();
            });
            this.main.find('.confirm').on('click', function () {
                if ($this.checkParams()) {
                    var params = $this.getParamsFormForm();
                    $this.setParams(params);
                    $this.setParamsToLs(params);

                    loading($containerObj.totalObj.queryData.bind($containerObj.totalObj));
                    $this.close();
                }
            });
            // 医院change事件
            this.formDataEl.hospital.on('change', function () {
                var selected = $(this).find('option:selected'),
                    selectedStr = '';
                for (var i = 0; i < selected.length; i++) {
                    selectedStr += selected.eq(i).text().split('[')[0];
                    selectedStr += (i === (selected.length - 1) ? '' : ',');
                }
                selectedStr += selected.length ? '<span class="clear-hospital">×</span>' : '';
                $headerObj.main.find('.hospital').html(selectedStr)
                    .find('.clear-hospital').off().on('click', function () {
                    $this.formDataEl.hospital.val('').trigger('change');
                    $this.params.hospitalId = null;
                    $containerObj.totalObj.queryData();
                });
            });
            // 设备类型change事件
            this.formDataEl.type.on('change', function () {
                var selected = $(this).find('option:selected'),
                    selectedStr = '';
                for (var i = 0; i < selected.length; i++) {
                    selectedStr += selected.eq(i).text().split('[')[0];
                    selectedStr += (i === (selected.length - 1) ? '' : ',');
                }
                selectedStr += selected.length ? '<span class="clear-type">×</span>' : '';
                $containerObj.top5Obj.main.find('.type').html(selectedStr)
                    .find('.clear-type').off().on('click', function () {
                    $this.formDataEl.type.val('').trigger('change');
                    $this.params.typeId = null;
                    $containerObj.totalObj.queryData();
                });
            });

            this.formDataEl.type.on('select2:select', function (param) {
                var typeIdArr = $('.select_type').val();
                var searchDataGlobal = $this.data.type;
                var id = param.params.data.id;
                if (id < 2016102346) {
                    for (var i = 0; i < searchDataGlobal[id].length; i++) {
                        typeIdArr.push(searchDataGlobal[id][i].id)
                    }
                }
                $this.formDataEl.type.val(typeIdArr).trigger('change');
            });
            this.formDataEl.type.on('select2:unselect', function (param) {
                var typeIdArr = $this.formDataEl.type.val();
                var searchDataGlobal = $this.data.type;
                var id = param.params.data.id;
                typeIdArr.removeByValue(id);
                if (id < 2016102346) {
                    for (var i = 0; i < searchDataGlobal[id].length; i++) {
                        typeIdArr.removeByValue(searchDataGlobal[id][i].id)
                    }
                }
                $this.formDataEl.type.val(typeIdArr).trigger('change');
            });
        }
    };

    loading();
    setTimeout($headerObj.init.bind($headerObj), 10);
});